package com.geo.geoProject.client.UI.fenetres;

import com.geo.geoProject.client.donneesStatiques.ApplicationGestion;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Widget;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.DragAppearance;
import com.smartgwt.client.widgets.Canvas;

public class MiniWindow  extends Canvas implements ResizeHandler {

    public MiniWindow(String contents, int left) {  
        setTop(50);
        setLeft(left);
        if (contents!=null)
        	setContents(contents);  
        setAlign(Alignment.CENTER);  
        setPadding(4);  
        setShowEdges(true);
        setBackgroundColor("#EEEEEE");  
        setKeepInParentRect(true);  
        setCanDragReposition(false);      
        setShowShadow(true) ;
        setShadowDepth(8) ;
        
    }
    
    public MiniWindow(String contents, int left, boolean shadowAndCentered) {
    	this(contents, left) ;
        setTop (Window.getClientHeight()/2-300);  
        setLeft(Window.getClientWidth()/2-300);  
        
        setDragAppearance(DragAppearance.TARGET);  
    }
    
    
    public MiniWindow(Widget contents, int left, boolean shadowAndCentered) {
    	this(null, left) ;
        setTop (Window.getClientHeight()/2-300);  
        setLeft(Window.getClientWidth()/2-300);  
   
        addChild(contents) ;

        setDragAppearance(DragAppearance.TARGET);  
    }
    public MiniWindow(Widget contenu, boolean centre, boolean deplacable, Canvas c) {
    	
        setAlign(Alignment.CENTER);  
        setPadding(4);  
        
        setShowEdges(true);
        setBackgroundColor("#EEEEEE");  
        
        setKeepInParentRect(true);  
        setCanDragReposition(deplacable);   
        
        setShowShadow(true) ;
        setShadowDepth(8) ;

        setDragAppearance(DragAppearance.TARGET);  

        if (contenu!=null)
        	addChild(contenu);
        
        if (c!=null)
        	c.addChild(this) ;

        if (centre) {
           	int largeur = this.getRight()-this.getLeft() ;
           	int hauteur = this.getBottom()-this.getTop() ;
           	
           	if (largeur==0)
           		largeur = 200 ;
           	if (hauteur==0)
           		hauteur = 200 ;
           	
        	ApplicationGestion.addWindowHandlet(this) ;
            setLeft(Window.getClientWidth() /2 - largeur /2);  
            setTop (Window.getClientHeight()/2 - hauteur /2);  
    	}

    
    }

	public void onResize(ResizeEvent event) {
       	int largeur = this.getRight()-this.getLeft() ;
       	int hauteur = this.getBottom()-this.getTop() ;
       	this.moveTo(Window.getClientWidth()/2 - largeur /2, Window.getClientHeight()/2 - hauteur /2) ;
	}
}
